home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7838 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  59 lines

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C calling C++ function????
  5. Date: Mon, 19 Feb 1996 18:26:56 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4gafce$84m@news.halcyon.com>
  8. References: <4g07q4$doh@ornews.intel.com> <DMvKCH.Iwo@tr.unisys.com>
  9. NNTP-Posting-Host: blv-pm12-ip19.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Something tells me it's not that simple.  
  13.  
  14. First, a 'C' compiler probably wouldn't know about the existence of a
  15. vtable, let alone that it can be accessed via .vtab as if it were a
  16. struct member.  When I say sizeof(myclass), I get the size of the data
  17. members exactly, no additional bytes suggesting function pointers or
  18. vtables.  You'll have to provide sample code I can compiler on MSVC4
  19. before I'll accept it.
  20.  
  21. Second, you seem to have forgotten about name mangling:
  22. bar() is really @@bar@4@lots_of_other_crap.  I don't believe you 
  23. can extern "C" methods, so the name will always be decorated somehow.
  24. If you knew the mangling, you could use that name, but then changing
  25. from VC2.2 to VC4.0 might break you, changing from VC to Gnu g++
  26. certainly would break you.
  27.  
  28. I believe the accepted thing to do is define a set of 'C' wrapper APIs
  29. that you can export to your 'C' modules.  Internally, your wrappers do
  30. class method calls.  
  31.  
  32.                     ---Norm 
  33.  
  34.  
  35. "Benjamin M. Romer" <bmr1@trpo4.tr.unisys.com> wrote:
  36.  
  37. >easy.
  38.  
  39. >if you want to call the foo object's bar function, you just need
  40. >to call
  41.  
  42. >foo.vtab->bar(foo, ...)
  43.  
  44. >vtab may be vftab or vfstab, can't remember off the top of my head,
  45. >though.
  46.  
  47. >Hope this helps.
  48.  
  49.  
  50. >Benjamin M. Romer
  51. >Software Engineer
  52. >Unisys Corporation
  53.  
  54. >#include <stddisclaim.h>
  55.  
  56.  
  57.  
  58.  
  59.